package com.poet.df.dbinfo.support;

import java.util.Map;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

import org.springframework.beans.factory.InitializingBean;

import com.poet.df.dbinfo.ConfigurableDbInfo;
import com.poet.df.dbinfo.pojo.Table;

public abstract class AbstractConfigurableDbInfo implements ConfigurableDbInfo,
		InitializingBean {

	/**
	 * 数据源
	 */
	protected DataSource dataSource;

	protected String[] types = new String[] { "TABLE" };

	/**
	 * 表数据缓存
	 */
	protected Map<String, Table> tablesCache = null;

	/**
	 * 表名称匹配
	 */
	protected String tableNamePattern;

	public String getTableNamePattern() {
		return tableNamePattern;
	}

	//@PostConstruct
	public void init() {
		this.loadDataBaseInfos();
	}

	@Override
	public void setTableNamePattern(String tableNamePattern) {
		this.tableNamePattern = tableNamePattern;
	}

	@Override
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		if (this.dataSource == null) {
			throw new Exception("DataSource must be Set!");
		}
	}

	@Override
	public void setTableTypes(String[] types) {
		if (types != null && types.length != 0) {
			this.types = types;
		}

	}

}
